package com.niit.controller.hive;

import java.sql.*;

public class YouTube1 {
    private static String driverClass = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {

        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = DriverManager.getConnection("jdbc:hive2://hadoop:10000/default","root","niit1234");
        Statement statement = connection.createStatement();

        String table_name ="youtube";
        String query1 = "select * from "+table_name+" where no_of_views%2=0 order by no_of_rating desc limit 20";

        ResultSet result = statement.executeQuery(query1);
        while(result.next()) {
            String id = result.getString(1);
            String uploader_name = result.getString(2);
            Integer no_of_days = result.getInt(3);
            String category = result.getString(4);
            Integer length = result.getInt(5);
            Integer no_of_views = result.getInt(6);
            Double rating = result.getDouble(7);
            Integer no_of_rating = result.getInt(8);
            String no_of_comments = result.getString(9);
        }
        result.close();
        statement.close();
        connection.close();

    }
}